import moment from "moment";

export default Vue => {
  // 格式化手机号码
  Vue.filter("phone", phone => {
    return phone.slice(0, 3) + "****" + phone.slice(7);
  });

  Vue.filter("date", date => {
    return moment(date).format("YYYY-MM-DD");
  });

  Vue.filter("time", date => {
    return moment(date).format("YYYY-MM-DD HH:mm:ss");
  });

  Vue.filter("money", value => {
    return `${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  });

  Vue.filter("number", (number, count = 1) => {
    number = number || 0;
    number = Number(number);
    if (number > 100000000) {
      return (number / 100000000).toFixed(2) + "亿";
    } else if (number > 10000) {
      return (number / 10000).toFixed(count) + "w";
    }

    if (`${number}`.indexOf(".") > -1) {
      return number.toFixed(count);
    }

    return number;
  });
};
